% File: testbench_macro_sc_fde_ib_snr_evolution.m
% -----------------------------------------------
% This script draws a series of snr evolution curves for a specific channel
% realization at various receiving snr's.

close all
clear all

load testbench_sc_fde_ib_evolution.mat

% var_tmp = 1e-8*(1: 1e4: 1e8);  % normalized var.
var_tmp = 1e-16*(1: 1e4: 1e8);  % normalized var.
% eb_n0   = (0:2:26);
% eb_n0   = (20:2:26);
eb_n0   = 28;
SNR     = eb_n0 + 10*log10(Cr*log2(M_mod)) - 10*log10(sf);
SINR    = zeros(length(SNR),length(var_tmp));
MSE     = zeros(size(SINR));

for n_snr = 1: length(SNR)
    noisePower_dB = xtxPower_mean_dB-SNR(n_snr);          % compute noise power
    noisePower    = 10^(noisePower_dB/10);            % convert backto linear scale
    noisePow_norm = noisePower/xtxPower_mean;         % noise power normalized to tx power
    sc_fde_ib_snr_evolution
    SINR(n_snr,:) = sinr_tmp;
    MSE(n_snr,:)  = mse_tmp;
end

%%
% load testbench_macro_sc_fde_ib_snr_evolution_28dB_1e-8_1e-16
% sinr = SINR;
% mse = MSE;
% load testbench_macro_sc_fde_ib_snr_evolution_28dB_1_1e-8
% SINR = [sinr SINR];
% MSE = [mse MSE];
% var_tmp = [1e-16*(1: 1e4: 1e8) 1e-8*(1: 1e4: 1e8)];
%%
figure();
semilogx(var_tmp, SINR);
set(gca,'XDir','reverse')
xlabel('Average Variance'); ylabel('SNR');
grid on
legend('Transfer Function of Equalizer', 'Location', 'NorthWest');
title('SNR Evolution Chart');

figure();
semilogx(var_tmp, MSE);
set(gca,'XDir','reverse')
xlabel('Average Variance'); ylabel('MSE');
grid on
legend('Transfer Function of Equalizer', 'Location', 'NorthEast');
title('MSE Evolution Chart');

filename = 'testbench_macro_sc_fde_ib_snr_evolution.mat';
save(filename, 'MSE', 'SNR', 'SINR', 'eb_n0', 'var_tmp');
%%
% End of script.